<extend name="layout/edit" />

<block name="HEADER">

</block>

<block name="CONTENT">
    <control:form id="purchase" />
</block>

<block name="FOOTER">
   <script type="text/javascript">
    var  page=(function(ns){
    	
		ns.init = function(){
			if(__mode=1 && window.__goods_id){
				purchase.setValue("goods_id",window.__goods_id);
				purchase.setValue("goods_name",window.__goods_name);
			}
			//设置总价
			purchase.on("input",'num',function(){
				ns.setTotalPrice();
			});
		}
		
		//商品选择规格
		ns.selectSpecs = function(){
	        var filter = {
	            url:"modules/common/selectGoodsSpecs",
	            mode:1,
	            goods_id: purchase.getValue('goods_id')
	        }
	        $.openIframe(filter,"选择商品规格",['600px', '480px']);
		}
    	ns.selectSpecsCallback = function(ids,data){
    		purchase.setValue("specs_id",data[0]['id']);
    		purchase.setValue("specs_name",data[0]['name']);
    		purchase.setValue("price",data[0]['sale_prices']);
    		ns.setTotalPrice();
    	}
    	
    	//设置总价
    	ns.setTotalPrice = function(){
    		var val = (purchase.getValue("price") * purchase.getValue("num")).toFixed(2);
    		purchase.setValue("total_price",val);
    	}
        
        //保存
        ns.save=function(){
        	var param = purchase.getData();
        	if(!param) return false;
        	if(!param.imgs){
        		return $.toast(0,'请上传凭证！');
        	};
        	purchase.save(4).then(function(res){
        		$.ajaxs('/admin/v1/Goods/addGoodsStatus',{ id:res.data });
        		purchase.opener.grid.load();
        		$.confirm("申请成功，请到进货申请记录查看申请记录！",function(){
        			purchase.opener.$.toast(1,"申请成功！");
        			$.close();
        		});
        	});
        }
        return ns;
    }({}));
    
    $(function(){ page.init(); });
   </script>
</block>



